<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.js"></script>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
    <script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>

    <!-- Bootstrap CSS -->
<!--    <link rel="stylesheet" href="/css/bootstrap.css">-->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css" rel="stylesheet">
    <script>
        $(function() {
            $.removeCookie('token', { path: '/' ,domain:".www.test.com"});
            $("#registerBtn").on("click",function () {
                location.href = "register.html";
            });
            // Handler for .ready() called.
            $("#submitBtn").on("click",function () {
                var email = $("#reg-email").val();
                var password = $("#reg-password").val();
                $.ajax({
                     //url: "http://localhost:9002/api/user/login/"+email+"/"+password,
                    url: "http://www.test.com/api/user/login/"+email+"/"+password,
                    type: "GET",
                    success:function (data) {
                        if(data == "false"){
                            alert("登陆失败")
                        }else{
                            location.href = "welcome.html";
                        }
                    }
                    //dataType: "text"
                })
            });

            $("#opBtn2").on("click",function () {
                $.ajax({
                    //url: "http://localhost:9002/api/user/login/"+email+"/"+password,
                    url: "http://www.test.com/kafka/send/topic_log",
                    type: "POST",
                    data : JSON.stringify(generateLogObj("login")),
                    success:function (data) {
                        alert("已发送1");
                    }
                    //dataType: "text"
                })
            });

            $("#opBtn3").on("click",function () {
                $.ajax({
                    //url: "http://localhost:9002/api/user/login/"+email+"/"+password,
                    url: "http://www.test.com/kafka/send/topic_log",
                    type: "POST",
                    data : JSON.stringify(generateLogObj("watch")),
                    success:function (data) {
                        alert("已发送2");
                    }
                    //dataType: "text"
                })
            });

            $("#opBtn4").on("click",function () {
                $.ajax({
                    //url: "http://localhost:9002/api/user/login/"+email+"/"+password,
                    url: "http://www.test.com/kafka/send/topic_log",
                    type: "POST",
                    data : JSON.stringify(generateLogObj("deliver")),
                    success:function (data) {
                        alert("已发送3");
                    }
                    //dataType: "text"
                })
            });

            function generateLogObj(operationString) {
                var day1 = new Date();
                var s1 = day1.toJSON();
                var log = {
                    userid : Math.random(),
                    acttime : s1,
                    action : operationString,
                    code : "company-"+ Math.random()
                };
                return log;
            }
        });
    </script>
    <title>Hello, world!</title>

</head>
<body>
<div class="container">
    <!-- Content here -->
    <form>
        <div class="form-group">
            <label for="reg-email">Email address</label>
            <input type="email" class="form-control" id="reg-email" aria-describedby="emailHelp">
            <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
        </div>
        <div class="form-group">
            <label for="reg-password">Password</label>
            <input type="password" class="form-control" id="reg-password">
        </div>
        <button type="button" id="submitBtn" class="btn btn-primary">登陆</button>
        <button type="button" id="registerBtn" class="btn btn-danger">注册</button>
    </form>
    <button type="button" id="opBtn2" class="btn btn-primary">模拟登陆发送kafka</button>
    <button type="button" id="opBtn3" class="btn btn-primary">模拟浏览发送kafka</button>
    <button type="button" id="opBtn4" class="btn btn-primary">模拟投递发送kafka</button>
</div>

</body>
</html>
